package com.shengwei.truck.driver.vm;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.shengwei.truck.driver.bean.JsonMsgListData;
import com.shengwei.truck.driver.bean.Result;
import com.shengwei.truck.driver.model.DataSource;
import com.shengwei.truck.driver.model.Repository;

/**
 * 消息列表
 */
public class MsgListViewModel extends ViewModel {
    private Repository mRepository; //M层引用
    MutableLiveData<Result<String>> mHasReadLiveData = new MutableLiveData<>();



    MutableLiveData<Result<String>> mHasReadAllLiveData = new MutableLiveData<>();
    MutableLiveData<Result<JsonMsgListData>> mMsgListLiveData = new MutableLiveData<>();

    public MsgListViewModel(Repository repository) {
        mRepository = repository;
    }
    public MsgListViewModel() {
        mRepository = Repository.getInstance(DataSource.getSingleInstance());
    }
    public MutableLiveData<Result<String>> getHasReadLiveData() {
        return mHasReadLiveData;
    }
    public MutableLiveData<Result<String>> getHasReadAllLiveData() {
        return mHasReadAllLiveData;
    }
    public MutableLiveData<Result<JsonMsgListData>> getMsgListLiveData() {
        return mMsgListLiveData;
    }

    /**
     * 列表项点击后，提交“消息已读”接口
     * @param msgId: 当前消息ID
     * @param isAll: 是否全部清除已读，1全部; 否则 0,只清除当前 msgId为已读
     */
    public void postHasRead(String msgId,int isAll) {
        MutableLiveData<Result<String>> liveData = null;
        if(isAll == 0){
            liveData = mHasReadLiveData;
        }
        else{
            liveData = mHasReadAllLiveData;
        }
        mRepository.postHasRead(msgId,isAll,liveData);
    }

    /**
     * @param pageNum: 分页页码
     * @param pageSize：每页显示的条目数
     * @param msgType： 消息类别
     */
    public void getMsgList(int pageNum,int pageSize,String msgType) {
        mRepository.getMsgList(pageNum,pageSize,msgType,mMsgListLiveData);
    }
}
